package net.bioteam.perl5;

/**
 * Demostrate how the Perl can be used.
 * @author jason
 *
 */
public class PerlTest {

	public static void main(String argv[]) {
		evalCode("{my $a=5; my $b=6; $a+$b;}", false);
		evalCode(" bad bad ", false);
		evalCode(" {my $str='test1357'; $str=~/\\d+/}", true);

		Thread tr = new Thread() {
			public void run() {
				System.out.println("***********run test in a thread ********");
				evalCode("{my $a=9; my $b=10; $a+$b;}", false);
				evalCode(" bad in thread bad ", false);
				evalCode(" {my $str='test1357'; $str=~/\\d+/}", true);
			}
		};
		tr.start();

	}

	public static void evalCode(String code, boolean b) {
		System.out.println("-------evaluating code " + code);
		try {
			if (!b) {

				String ret = Perl.eval(code);
				System.out.println("result is " + ret);
			} else {
				boolean ret = Perl.evalBoolean(code);
				System.out.println("result is " + ret);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
